package net.xdclass.request;

import java.io.Serializable;
import java.util.List;

/**
 * @author zhaowei
 * @Description TODO
 * @Remark 有问题直接联系我
 * @Version 1.0
 **/
public class  Pageable<T> implements Serializable {

    private static final long serialVersionUID = -7661251690281633793L;
    protected int currentPage;
    protected int pageSize;
    protected long total;
    protected int pages;
    protected List<T> records;

    public Pageable() {
    }

    public Pageable(int currentPage, int pageSize, long total, List<T> records) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.total = total;
        this.records = records;
        this.initPage();
    }

    public Pageable(int currentPage, int pageSize, long total, int pages, List<T> records) {
        this(currentPage, pageSize, total, records);
        this.pages = pages;
    }

    public int getCurrentPage() {
        return this.currentPage;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public long getTotal() {
        return this.total;
    }

    public int getPages() {
        return this.pages;
    }

    public List<T> getRecords() {
        return this.records;
    }

    public void initPage() {
        if (this.pages == 0 && this.pageSize != 0) {
            this.pages = (int) (this.total % (long) this.pageSize == 0L ? this.total / (long) this.pageSize : (this.total - this.total % (long) this.pageSize) / (long) this.pageSize + 1L);
        }

    }


    @Override
    public String toString() {
        return "Pageable{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", total=" + total +
                ", pages=" + pages +
                ", records=" + records +
                '}';
    }
}